package com.jesse.base;

import com.jesse.main.R;
import com.jesse.util.ViewUtil;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;

public class BaseActivity extends Activity {
	private float xDown;
	private float xUp;
	private boolean isOverFIXED;
	private final int FIXED = (int) (ViewUtil.getScreenWidth() * 0.2);
	public boolean gestrue = true;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_base);
		ViewUtil.setContext(this);
	}
	
	//手勢开关
	public boolean isGestrue() {
		return gestrue;
	}
	
	public void setGestrue(boolean gestrue) {
		this.gestrue = gestrue;
	}
	
	@Override
	public boolean dispatchTouchEvent(MotionEvent event) {
		int action = event.getAction();
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			xDown = event.getX();
			break;
		case MotionEvent.ACTION_UP:
			xDown = 0;
			xUp = 0;
			break;
		case MotionEvent.ACTION_MOVE:
			xUp = event.getX();
			isOverFIXED = xUp - xDown > FIXED ? true : false;
			if (isOverFIXED && gestrue) {
				finish();
				return true;
			}
			break;
		}
		return super.dispatchTouchEvent(event);
	}
	
	public void finish() {
		ViewUtil.endWaiting();
		ViewUtil.closePopup();
		super.finish();
		overridePendingTransition(0, R.anim.out_to_left);
	}
	
	@Override
    protected void onDestroy() {
        ViewUtil.hideKeyBoard();
        ViewUtil.removeContext(this);
        ViewUtil.Debug("container remove");
        super.onDestroy();
    }
}
